package com.sweets.look.ui.view;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;

import com.sweets.look.R;
import com.sweets.look.util.ViewHelper;
import com.sweets.look.util.ViewUtils;

/**
 * Author   Shone
 * Date     20/08/16.
 * Github   https://github.com/shonegg
 */
public class NavigationBarView extends View {


    public NavigationBarView(Context context) {
        this(context, null);
    }

    public NavigationBarView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public NavigationBarView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init();
    }

    private void init() {
        this.setBackgroundColor(getResources().getColor(android.R.color.transparent));
    }

    @Override
    public void onMeasure(int widthSpec, int heightSpec) {
        super.onMeasure(widthSpec, heightSpec);
        adjustHeight();
    }

    @Override
    public void invalidate() {
        super.invalidate();
        adjustHeight();
    }

    public void adjustHeight() {
        if (ViewHelper.checkDeviceHasNavigationBar(getContext())) {
            ViewGroup.LayoutParams params = getLayoutParams();
            params.height = ViewHelper.getNavigationBarHeight(getContext());
        } else {
            ViewGroup.LayoutParams params = getLayoutParams();
            params.height = ViewUtils.convertToDensityPixels(getContext(), 5);
        }
    }
}
